package com.qcy.serve.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qcy.common.annotation.Log;
import com.qcy.common.core.controller.BaseController;
import com.qcy.common.core.domain.AjaxResult;
import com.qcy.common.enums.BusinessType;
import com.qcy.serve.domain.Weapon;
import com.qcy.serve.service.IWeaponService;
import com.qcy.common.utils.poi.ExcelUtil;
import com.qcy.common.core.page.TableDataInfo;

/**
 * 武器数据Controller
 * 
 * @author qcy
 * @date 2025-09-25
 */
@RestController
@RequestMapping("/serve/weapon")
public class WeaponController extends BaseController
{
    @Autowired
    private IWeaponService weaponService;

    /**
     * 查询武器数据列表
     */
    @PreAuthorize("@ss.hasPermi('serve:weapon:list')")
    @GetMapping("/list")
    public TableDataInfo list(Weapon weapon)
    {
        startPage();
        List<Weapon> list = weaponService.selectWeaponList(weapon);
        return getDataTable(list);
    }

    /**
     * 导出武器数据列表
     */
    @PreAuthorize("@ss.hasPermi('serve:weapon:export')")
    @Log(title = "武器数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Weapon weapon)
    {
        List<Weapon> list = weaponService.selectWeaponList(weapon);
        ExcelUtil<Weapon> util = new ExcelUtil<Weapon>(Weapon.class);
        util.exportExcel(response, list, "武器数据数据");
    }

    /**
     * 获取武器数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('serve:weapon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(weaponService.selectWeaponById(id));
    }

    /**
     * 新增武器数据
     */
    @PreAuthorize("@ss.hasPermi('serve:weapon:add')")
    @Log(title = "武器数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Weapon weapon)
    {
        return toAjax(weaponService.insertWeapon(weapon));
    }

    /**
     * 修改武器数据
     */
    @PreAuthorize("@ss.hasPermi('serve:weapon:edit')")
    @Log(title = "武器数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Weapon weapon)
    {
        return toAjax(weaponService.updateWeapon(weapon));
    }

    /**
     * 删除武器数据
     */
    @PreAuthorize("@ss.hasPermi('serve:weapon:remove')")
    @Log(title = "武器数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(weaponService.deleteWeaponByIds(ids));
    }
}
